//
//  InformationComparisonViewController.m
//  ICrEAM
//
//  Created by Leona on 2017/4/20.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "InformationComparisonViewController.h"
#import "ProvinceCityRespose.h"
@interface InformationComparisonViewController ()
@property (weak, nonatomic) IBOutlet UILabel *vinLabel;
@property (weak, nonatomic) IBOutlet UILabel *licenseLabel;
@property (weak, nonatomic) IBOutlet UILabel *salesDateLable;
@property (weak, nonatomic) IBOutlet UILabel *modelLabel;
@property (weak, nonatomic) IBOutlet UILabel *carLifeLabel;
@property (weak, nonatomic) IBOutlet UILabel *userName;
@property (weak, nonatomic) IBOutlet UILabel *userProperTyLabel;
@property (weak, nonatomic) IBOutlet UILabel *provincenL;
@property (weak, nonatomic) IBOutlet UILabel *cityLabel;
@property (weak, nonatomic) IBOutlet UILabel *countryLabel;
@property (weak, nonatomic) IBOutlet UILabel *carNatureL;
@property (weak, nonatomic) IBOutlet UILabel *cantactNameL;
@property (weak, nonatomic) IBOutlet UILabel *contactMobieL;
@property (weak, nonatomic) IBOutlet UILabel *personSexL;

//label
@property (weak, nonatomic) IBOutlet UILabel *headVinLabel;
@property (weak, nonatomic) IBOutlet UILabel *headCarNumberLabel;
@property (weak, nonatomic) IBOutlet UILabel *headSaleDataLabel;
@property (weak, nonatomic) IBOutlet UILabel *headNatureLabel;
@property (weak, nonatomic) IBOutlet UILabel *headCarModelLabel;
@property (weak, nonatomic) IBOutlet UILabel *headCarLifeLabel;
@property (weak, nonatomic) IBOutlet UILabel *headOwnerNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *headOwnerNatureLabel;
@property (weak, nonatomic) IBOutlet UILabel *headLinkManNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *headLinkManPhoneLabel;
@property (weak, nonatomic) IBOutlet UILabel *headOwnerSexLabel;

@property (weak, nonatomic) IBOutlet UILabel *headProvincenLabel;

@property (weak, nonatomic) IBOutlet UILabel *headCityLabel;
@property (weak, nonatomic) IBOutlet UILabel *headCountryLabel;
@property (weak, nonatomic) IBOutlet UILabel *viewTitleLabel;











@end

@implementation InformationComparisonViewController
- (IBAction)sureAction:(id)sender {
    [self removeAdImageView];
    if (self.sureBlock) {
        self.sureBlock();
    }
}
- (IBAction)cancelAction:(id)sender {
        [self removeAdImageView];
     [self removeFromParentViewController];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    _headVinLabel.textColor = TitleColor;
    _headCarNumberLabel.textColor = TitleColor;
    _headSaleDataLabel.textColor = TitleColor;
    _headNatureLabel.textColor = TitleColor;
    _headCarModelLabel.textColor = TitleColor;
    _headCarLifeLabel.textColor = TitleColor;
    _headOwnerNameLabel.textColor = TitleColor;
    _headOwnerNatureLabel.textColor = TitleColor;
    _headLinkManNameLabel.textColor = TitleColor;
    _headLinkManPhoneLabel.textColor = TitleColor;
    _headOwnerSexLabel.textColor = TitleColor;
    _headProvincenLabel.textColor = TitleColor;
    _headCityLabel.textColor = TitleColor;
    _headCountryLabel.textColor = TitleColor;
    _viewTitleLabel.textColor = TitleColor;
    
    [_continueButton setBackgroundColor:TitleColor];
    [_backoutButton setBackgroundColor:TitleColor];
    

    //vin
    self.vinTextfield.text=self.model.VIN;
    //车牌
    self.carNumberTextField.text=self.model.LICENSE;
    //购车日期
    self.billDataTextField.text=[ICrEAMTool getDateWithTimeInterval:self.model.SALES_DATE];
    
    ParameterModel *natureModel=[ICrEAMTool getCodeModelForCode:self.model.BUSINESS_KIND];
    if (natureModel) {
            self.carNatureTextField.text=natureModel.desc;
    }

    self.carModelTextField.text=self.model.MODEL_NAME;
    
    ParameterModel *lifeModel=[ICrEAMTool getCodeModelForCode:self.model.VEHICLE_LIFE_STATUS];
    if (lifeModel) {
        self.carStateOfLifeTextField.text = lifeModel.desc;
    }
  
    self.onwerNameTextField.text=self.model.OWNER_NAME;
    ParameterModel *onwerNatureModel=[ICrEAMTool getCodeModelForCode:self.model.OWNER_PROPERTY];
    if (onwerNatureModel) {
        self.onwerNatureTextField.text=onwerNatureModel.desc;
    }
   
    self.linkManNameTextField.text=self.model.CONTACTOR_NAME;
    self.linkManPhoneTextField.text=self.model.CONTACTOR_MOBILE;
    ParameterModel *genderModel=[ICrEAMTool getCodeModelForCode:self.model.GENDER];
    if (genderModel) {
        self.onwerSexTextField.text=genderModel.desc;
    }

    self.provinceTextField.text= [self getCityDataWithCode:self.model.PROVINCE Type:0] ;
    self.cityTextField.text= [self getCityDataWithCode:self.model.CITY Type:1];
    self.areaTextField.text= [self getCityDataWithCode:self.model.DISTRICT Type:2];
    
//    self.vinLabel.text=self.carModel.vinNum;
    self.licenseLabel.text=self.carModel.carNum;
    self.salesDateLable.text=[ICrEAMTool getDateWithTimeInterval:self.carModel.parchaseDate];
    self.modelLabel.text=self.carModel.carTypeName;
    
    ParameterModel *lifeTopModel=[ICrEAMTool getCodeModelForCode:self.carModel.VEHICLE_LIFE_STATUS];
    if (lifeTopModel) {
        self.carLifeLabel.text=lifeTopModel.desc;
    }

    self.userName.text=self.personModel.ownerName;
    
    ParameterModel *onwerTopNatureModel=[ICrEAMTool getCodeModelForCode:self.personModel.ownerType];
    if (onwerTopNatureModel) {
        self.userProperTyLabel.text=onwerTopNatureModel.desc;
    }
 
    self.provincenL.text= [self getCityDataWithCode:self.personModel.province Type:0];
    self.cityLabel.text=[self getCityDataWithCode:self.personModel.city Type:1];
    self.countryLabel.text=[self getCityDataWithCode:self.personModel.district Type:2];
    
    ParameterModel *natureTopModel=[ICrEAMTool getCodeModelForCode:self.carModel.carUses];
    if (natureTopModel) {
        self.carNatureL.text=natureTopModel.desc;
    }
    self.cantactNameL.text=self.personModel.CONTACTOR_NAME;
    self.contactMobieL.text=self.personModel.CONTACTOR_MOBILE;
    ParameterModel *genderTopModel=[ICrEAMTool getCodeModelForCode:self.personModel.gender];
    if (genderTopModel) {
        self.personSexL.text=genderTopModel.desc;
    }

    
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void)showOnView:(UIWindow *)window
{
    CGRect frame = [UIScreen mainScreen].bounds;
    
//    CGFloat height=with*
//    self.view.frame = CGRectMake(0, 200, 550, 450);
    self.view.frame=frame;
    [window addSubview:self.view];
    if (!IOS7_OR_LATER) {
        frame.origin.y = 20;
        frame.size.height-=20;
    }
    
}
- (void)setDismissBlock:(ICrEAMBlock)block
{
    if (block != dismissBlock) {
        dismissBlock = [block copy];
    }
}
//移除页面
- (void)removeAdImageView
{
    [UIView animateWithDuration:3.0f animations:^{
        //        self.bgView.alpha = 0.999f;
    } completion:^(BOOL finished) {
        //        [self.bgView removeFromSuperview];
        
        [self.view removeFromSuperview];
        if (dismissBlock) {
            dismissBlock();
        }
    }];
    
}
- (void)animationFinished{
    [self removeAdImageView];
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    self.view.backgroundColor=[UIColor clearColor];
    CGContextRef contentext = UIGraphicsGetCurrentContext();
    
    [UIView beginAnimations:nil context:contentext];
    
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    
    [UIView setAnimationDuration:0.7];
    
    self.view.transform = CGAffineTransformMakeTranslation(self.view.width, 0);
    
    [UIView setAnimationDelegate:self];
    
    [UIView setAnimationDidStopSelector:@selector(animationFinished) ];
    
    [UIView commitAnimations];
}
//根据code来查找省市县区
- (NSString *)getCityDataWithCode:(NSString *)code Type:(int)type
{
    NSArray *array  = [ICrEAMTool getProvinceCityArray];
    if(type == 0)
    {
        //查询省
        for(int i = 0;i<array.count;i++)
        {
            NSArray *tempProvinceArray = array[i];
            ProvinceModel *provinceData = tempProvinceArray[0];
            if([provinceData.provinceCode isEqualToString:code])
            {
                return provinceData.provinceName;
            }
            
        }
        
    }
    if(type == 1)
    {
        //查询市
        for(int i = 0;i<array.count;i++)
        {
            NSArray *tempProvinceArray = array[i];
            ProvinceModel *provinceData = tempProvinceArray[0];
            NSArray *tempCityArray = provinceData.cityList;
            for(int j = 0;j<tempCityArray.count;j++)
            {
                CityModel *citydata = tempCityArray[j];
                if([citydata.cityCode isEqualToString:code])
                {
                    return citydata.cityName;
                }
            }
            
        }
    }
    if(type == 2)
    {
        //查询县区
        for(int i = 0;i<array.count;i++)
        {
            NSArray *tempProvinceArray = array[i];
            ProvinceModel *provinceData = tempProvinceArray[0];
            NSArray *tempCityArray = provinceData.cityList;
            for(int j = 0;j<tempCityArray.count;j++)
            {
                CityModel *citydata = tempCityArray[j];
                NSArray *tempDisArray = citydata.districtyList;
                for(int z = 0;z<tempDisArray.count;z++)
                {
                    DistrictModel *disData = tempDisArray[z];
                    if([disData.distCode isEqualToString:code])
                    {
                        return disData.distName;
                    }
                }
            }
            
        }
    }
    return @"";
}
@end
